package example02;

import java.awt.*;
import javax.swing.*;
import net.sf.jeppers.grid.*;

/**
 * @author grom
 */
public class StyleGridDemo extends JFrame {	
	public StyleGridDemo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
        JGrid grid = new JGrid();
        for (int col = 0; col < grid.getColumnCount(); col++) {
            grid.setColumnWidth(col, 50);
            for (int row = 0; row < grid.getRowCount(); row++) {
                int k = row * grid.getColumnCount() + col;
                if ((col + row) % 2 != 0) {
                    k = -k;
                }
                grid.setValueAt(new Integer(k), row, col);
            }
        }
        
        // Add custom renderer
        ((DefaultStyleModel)grid.getStyleModel()).setRenderer(Integer.class, new NumberRenderer());
		
		JScrollGrid scrollGrid = new JScrollGrid(grid);
		scrollGrid.setShowHeaders(false);
		getContentPane().add(scrollGrid, BorderLayout.CENTER);
		
		pack();
	}
	
	public static void main(String[] args) {
	  StyleGridDemo sg = new StyleGridDemo();

	  Dimension big=Toolkit.getDefaultToolkit().getScreenSize();
	  Dimension small=sg.getSize();
	  sg.setLocation((big.width-small.width)/2,
					 (big.height-small.height)/2);

	  sg.setVisible(true);
	}	
}
